<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const a = {
            num: 1,
            hobbit: ['学习', '看视频', '敲代码'],
            student: {
                uname: '杨桑',
                age: '18',
                hobbit: ['打篮球', '学习', '看视频', '敲代码'],
            },
            x: undefined,
        }
//请用递归的方式深拷贝a对象为b对象
function clone (old)  {
    // 声明变量
    let newdata 
    if(old instanceof Array){
        newdata=[]
        for(let i =0;i<old.length;i++){
            newdata[i]=clone (old[i])
        }
    }
    else if(old instanceof Object){
        newdata={}
        for (const key in old) {
           newdata[key]=clone(old[key])
                
            }
        }
        else{
            newdata=old
        }
        return newdata
    }
let b =clone(a)
console.log(b);
    </script>
</body>

</html>